package com.cloudkinto.service.order.makeshop.impl;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.cloudkinto.annotate.GraphqlResultAttributesBuilder;
import com.cloudkinto.bo.order.makeshop.MakeShopErrorResponse;
import com.cloudkinto.bo.order.makeshop.MakeShopShopConfig;
import com.cloudkinto.bo.order.makeshop.getOrder.*;
import com.cloudkinto.bo.order.makeshop.getProduct.SearchProductRequest;
import com.cloudkinto.bo.order.makeshop.getProduct.SearchProductResponse;
import com.cloudkinto.bo.order.makeshop.getProduct.SearchedProduct;
import com.cloudkinto.bo.order.makeshop.getProductStock.SearchProductQuantityRequest;
import com.cloudkinto.bo.order.makeshop.getProductStock.SearchProductQuantityResponse;
import com.cloudkinto.bo.order.makeshop.getProductStock.SearchedProductQuantity;
import com.cloudkinto.common.utils.OkHttpUtils;
import com.cloudkinto.common.utils.dict.StaticDict;
import com.cloudkinto.dao.PlatformStoreDao;
import com.cloudkinto.entity.PlatformOrderDo;
import com.cloudkinto.entity.PlatformOrderProductDo;
import com.cloudkinto.entity.PlatformProductDo;
import com.cloudkinto.enumType.common.CountryEnum;
import com.cloudkinto.service.order.makeshop.MakeShopApiService;
import com.cloudkinto.service.platform.*;
import com.cloudkinto.service.product.ProductService;
import com.cloudkinto.utils.MakeShopGraphqlUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.apache.commons.codec.binary.Hex;
import org.mountcloud.graphql.request.param.RequestObjectParameter;
import org.mountcloud.graphql.request.result.ResultAttributtes;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static com.cloudkinto.common.utils.RakutenUtil.createSPHeader;

/**
 * @author long
 * @Description make shop api对接
 * @Date 2025/4/25 10:37
 */
@Service
@Transactional(rollbackFor = Exception.class)
@RequiredArgsConstructor
@Slf4j
public class MakeShopApiServiceImpl implements MakeShopApiService {

    private final MakeShopConfig makeShopConfig;
    private final PlatformOrderService platformOrderService;
    private final PlatformOrderProductService platformOrderProductService;
    private final PlatformProductService platformProductService;
    private final PlatformStoreDao platformStoreDao;
    private final PlatformProductMappingService platformProductMappingService;
    private final PlatformOrderPackageDetailService platformOrderPackageDetailService;
    private final ProductService productService;
    private static final String DATE_TIME_REGEX =
            "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01]) ([01]\\d|2[0-3]):([0-5]\\d):([0-5]\\d)$";
    private static final String DATE_TIME_REGEX2 =
            "^\\d{4}(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])([01]\\d|2[0-3])([0-5]\\d){2}$";

    /**
     * 获取签名
     *
     * @param str 加密前的字符串
     * @return 加密后的字符串
     */
    private String getSign(String str) {
        String encodeStr = null;
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
            byte[] hash = messageDigest.digest(str.getBytes(StandardCharsets.UTF_8));
            //这里用的是hutool工具栏编码
            encodeStr = Base64.encode(Hex.encodeHexString(hash));
        } catch (NoSuchAlgorithmException e) {
            log.error("生成签名失败:{} ", e.getMessage());
            e.printStackTrace();
        }
        return encodeStr;
    }

    @Override
    @Deprecated
    public <T> T postToMakeShop(String apiName, Object data, Class<T> clazz) throws Exception {
        String sign = getSign(makeShopConfig.getToken());
        System.out.println("sign:" + sign);
        Map<String, String> headerMap = new HashMap<>(8);
        headerMap.put("content-type", "application/json");
        headerMap.put("authorization", sign);
        headerMap.put("x-api-key", makeShopConfig.getApiKey());
        headerMap.put("x-timestamp", String.valueOf(DateUtil.date().setTimeZone(TimeZone.getTimeZone("GMT+9")).getTime() / 1000));
        String url = makeShopConfig.getUrl() + apiName;
        OkHttpClient client = OkHttpUtils.getUnsafeOkHttpClient();
        OkHttpClient.Builder builder = client.newBuilder();
        builder.connectTimeout(60, TimeUnit.SECONDS)
                .readTimeout(60, TimeUnit.SECONDS)
                .writeTimeout(60, TimeUnit.SECONDS)
                .retryOnConnectionFailure(false);
        Request.Builder requestBuilder = createSPHeader(headerMap);
        Request request = requestBuilder.url(url)
                .post(RequestBody.create(MediaType.parse("application/json"), JSONUtil.toJsonStr(data)))
                .build();
        Response response;
        String body = null;
        response = builder.build().newCall(request).execute();
        if (response.body() != null) {
            body = response.body().string();
        }
        if (StrUtil.isBlank(body)) {
            throw new Exception("make shop api 调用失败:" + response.message());
        }
        String bodyJson = JSONUtil.toJsonStr(body);
        if (bodyJson.contains("errors")) {
            MakeShopErrorResponse makeShopErrorResponse = JSONUtil.toBean(bodyJson, MakeShopErrorResponse.class);
            throw new Exception(makeShopErrorResponse.getErrors().stream().map(MakeShopErrorResponse.MakeShopError::getMessage).collect(Collectors.joining(",")));
        }
        if (response.code() != 200) {
            throw new Exception("make shop api 调用失败:" + bodyJson);
        }
        return JSONUtil.toBean(bodyJson, clazz);
    }

    /**
     * 验证日期格式是否正确 yyyy-MM-dd HH:mm:ss
     *
     * @param input 日期字符串
     * @return true/false
     */
    public static boolean regexCheckDate1(String input) {
        return Pattern.matches(DATE_TIME_REGEX, input);
    }

    /**
     * 验证日期格式是否正确 yyyyMMddHHmmss
     *
     * @param input 日期字符串
     * @return true/false
     */
    public static boolean regexCheckDate2(String input) {
        return Pattern.matches(DATE_TIME_REGEX2, input);
    }

    @Override
    public void getOrderList() throws Exception {
        SearchOrderRequest searchOrderRequest = new SearchOrderRequest();
        searchOrderRequest.setPage(1);
        searchOrderRequest.setLimit(1);
        String date = DateUtil.format(DateUtil.date(), "yyyyMMdd");
        searchOrderRequest.setStartOrderDate(date + "000000");
        searchOrderRequest.setEndOrderDate(date + "235959");
        ResultAttributtes[] resultAttributtes = GraphqlResultAttributesBuilder.build(SearchOrderResponse.class);
        Map<String, Object> request = new HashMap<>(2);
        request.put("input", new RequestObjectParameter(searchOrderRequest));
        SearchOrderResponse searchOrder = MakeShopGraphqlUtils.postGraphqlQuery(MakeShopShopConfig.builder().build(), "searchOrder", request, SearchOrderResponse.class, resultAttributtes);
        log.info(String.valueOf(searchOrder));
        if (Objects.nonNull(searchOrder) && CollUtil.isNotEmpty(searchOrder.getOrders())) {
            List<SearchedOrder> orders = searchOrder.getOrders();
            // 获取平台订单号
            List<String> platNoList = orders.stream().map(SearchedOrder::getDisplayOrderNumber).collect(Collectors.toList());
            // 查询库内平台订单
            Map<String, PlatformOrderDo> platNoMatchOrder = new HashMap<>();
            if (CollUtil.isNotEmpty(platNoList)) {
                platNoMatchOrder = platformOrderService.lambdaQuery().eq(PlatformOrderDo::getPlatformCode, StaticDict.Store_PlatformCode.Makeshop.getValue()).in(PlatformOrderDo::getPlatformOrderNo, platNoList)
                        .list().stream().collect(Collectors.toMap(PlatformOrderDo::getPlatformOrderNo, val -> val, (o1, o2) -> o1));
            }
            List<PlatformOrderDo> orderDoList = new ArrayList<>(orders.size());
            List<PlatformOrderProductDo> orderProductDoList = new ArrayList<>(orders.size() * 3);
            for (SearchedOrder searchedOrder : orders) {
                PlatformOrderDo platformOrderDo = this.buildCommonOrderInfo(searchedOrder);
                // 平台订单号匹配本地数据
                PlatformOrderDo existPlatOrder = platNoMatchOrder.get(searchedOrder.getDisplayOrderNumber());
                //判断更新时间，如果本地更新时间小于平台更新时间，更新本地订单
                if (Objects.nonNull(existPlatOrder) && Objects.nonNull(existPlatOrder.getLastUpdateDate()) && existPlatOrder.getLastUpdateDate().getTime() >= DateUtil.parse(searchedOrder.getModified(), "yyyyMMddHHmmss").getTime()) {
                    continue;
                }
                if (Objects.nonNull(existPlatOrder)) {
                    platformOrderDo.setId(existPlatOrder.getId());
                }
                //配送信息
                List<DeliveryInfo> deliveryInfos = searchedOrder.getDeliveryInfos();
                //按配送状态分
                Map<String, DeliveryInfo> deliveryStatusMap = deliveryInfos.stream()
                        .filter(i -> StrUtil.isNotBlank(i.getDeliveryStatus()))
                        .collect(Collectors.toMap(DeliveryInfo::getDeliveryStatus, val -> val, (o1, o2) -> o1));
                /*
                  配送状态 N：未処理 Y：配送完了 C：キャンセル R：返送
                 */
                // todo 待定 订单部分完成 部分退货？？？
                if (deliveryStatusMap.containsKey("C")) {
                    // todo 状态流转wms？？
                    //订单取消方式
                    platformOrderDo.setCancelWay(0);
                    platformOrderDo.setStatus(StaticDict.Platform_Order_Status.Four.getValue());
                    DeliveryInfo deliveryInfo = deliveryStatusMap.get("C");
                    this.buildOrderProductInfoAndDeliveryInfo(platformOrderDo, deliveryInfo, orderProductDoList);
                } else if (deliveryStatusMap.containsKey("Y")) {
                    platformOrderDo.setStatus(StaticDict.Platform_Order_Status.Three.getValue());
                    DeliveryInfo deliveryInfo = deliveryStatusMap.get("Y");
                    this.buildOrderProductInfoAndDeliveryInfo(platformOrderDo, deliveryInfo, orderProductDoList);
                } else if (deliveryStatusMap.containsKey("N")) {
                    platformOrderDo.setStatus(StaticDict.Platform_Order_Status.Zero.getValue());
                    DeliveryInfo deliveryInfo = deliveryStatusMap.get("N");
                    this.buildOrderProductInfoAndDeliveryInfo(platformOrderDo, deliveryInfo, orderProductDoList);
                } else if (deliveryStatusMap.containsKey("R")) {

                }
                orderDoList.add(platformOrderDo);
            }
            //更新平台产品信息 todo 处理wms分包？？？
            if (CollUtil.isNotEmpty(orderDoList)) {
                platformOrderService.saveOrUpdateBatch(orderDoList);
            }
            if (CollUtil.isNotEmpty(orderProductDoList)) {
                Map<String, Long> platNoMatchId = orderDoList.stream().collect(Collectors.toMap(PlatformOrderDo::getPlatformOrderNo, PlatformOrderDo::getId));
                orderProductDoList.forEach(i -> i.setOrderId(platNoMatchId.get(i.getPlatformOrderNo())));
                platformOrderProductService.saveBatch(orderProductDoList);
            }
        }
    }

    /**
     * 构建订单基本信息
     *
     * @param searchedOrder 请求返回订单信息
     * @return 平台订单对象
     */
    private PlatformOrderDo buildCommonOrderInfo(SearchedOrder searchedOrder) {
        PlatformOrderDo platformOrderDo = new PlatformOrderDo();
        if (Objects.isNull(searchedOrder)) {
            return platformOrderDo;
        }
        platformOrderDo.setOrderNo(searchedOrder.getSystemOrderNumber());
        platformOrderDo.setPlatformOrderNo(searchedOrder.getDisplayOrderNumber());
        platformOrderDo.setPlatformCode(StaticDict.Store_PlatformCode.Makeshop.getValue());
//        platformOrderDo.setStoreId();
        platformOrderDo.setBuyerName(searchedOrder.getSenderName());
        platformOrderDo.setBuyerEmail(searchedOrder.getSenderEmail());
        platformOrderDo.setBuyerPostcode(searchedOrder.getSenderPost());
        platformOrderDo.setBuyerTelephone(searchedOrder.getSenderTel());
        String buyerAddress = (StrUtil.isNotBlank(searchedOrder.getSenderPrefecture()) ? searchedOrder.getSenderPrefecture() : "")
                + (StrUtil.isNotBlank(searchedOrder.getSenderAddress()) ? searchedOrder.getSenderAddress() : "")
                + (StrUtil.isNotBlank(searchedOrder.getSenderAddress2()) ? searchedOrder.getSenderAddress2() : "");
        platformOrderDo.setBuyerAddress(buyerAddress);
        platformOrderDo.setTotalAmount(BigDecimal.valueOf(searchedOrder.getSumPrice()));
        platformOrderDo.setCurrencyCode(CountryEnum.JP.getCurrency());
        if (StrUtil.isNotBlank(searchedOrder.getOrderDate())) {
            if (regexCheckDate1(searchedOrder.getOrderDate())) {
                platformOrderDo.setOrderTime(DateUtil.parse(searchedOrder.getOrderDate(), "yyyy-MM-dd HH:mm:ss"));
            }
        }
        if (StrUtil.isNotBlank(searchedOrder.getModified())) {
            if (regexCheckDate2(searchedOrder.getModified())) {
                platformOrderDo.setLastUpdateDate(DateUtil.parse(searchedOrder.getModified(), "yyyyMMddHHmmss"));
            }
        }
        if (StrUtil.isNotBlank(searchedOrder.getPaymentDate())) {
            if (regexCheckDate1(searchedOrder.getPaymentDate())) {
                platformOrderDo.setPayTime(DateUtil.parse(searchedOrder.getPaymentDate(), "yyyy-MM-dd HH:mm:ss"));
            }
        }
        platformOrderDo.setSource("api");
        platformOrderDo.setSettlementModel(searchedOrder.getPayMethod());
        return platformOrderDo;
    }

    /**
     * 构建订单商品信息及配送信息（收件人信息等等）
     */
    private void buildOrderProductInfoAndDeliveryInfo(PlatformOrderDo platformOrderDo, DeliveryInfo deliveryInfo, List<PlatformOrderProductDo> orderProductDoList) {
        platformOrderDo.setReceiver(deliveryInfo.getReceiverName());
        platformOrderDo.setTelephone(deliveryInfo.getReceiverTel());
        platformOrderDo.setCountryRegionCode(CountryEnum.JP.getValue());
        platformOrderDo.setDistrict(deliveryInfo.getReceiverPrefecture());
        platformOrderDo.setCityCode(deliveryInfo.getReceiverAddress());
        platformOrderDo.setAddressOne(deliveryInfo.getReceiverAddress2());
        platformOrderDo.setPostcode(deliveryInfo.getReceiverPost());
        if (StrUtil.isNotBlank(deliveryInfo.getEstimatedShipmentDate())) {
            if (regexCheckDate1(deliveryInfo.getEstimatedShipmentDate())) {
                platformOrderDo.setShipTime(DateUtil.parse(deliveryInfo.getEstimatedShipmentDate(), "yyyy-MM-dd HH:mm:ss"));
            }
        }
        if (StrUtil.isNotBlank(deliveryInfo.getDesiredDeliveryDate())) {
            platformOrderDo.setDeliveryDate(deliveryInfo.getDesiredDeliveryDate());
        }
        if (StrUtil.isNotBlank(deliveryInfo.getDesiredDeliveryTimezone())) {
            platformOrderDo.setDeliveryTimeName(deliveryInfo.getDesiredDeliveryTimezone());
        }
        if (StrUtil.isNotBlank(deliveryInfo.getSlipNumber())) {
            platformOrderDo.setTrackNo(deliveryInfo.getSlipNumber());
        }
        platformOrderDo.setPostagePrice(BigDecimal.valueOf(deliveryInfo.getShippingCharge()));
        if (Objects.nonNull(platformOrderDo.getId())) {
            return;
        }
        List<BasketInfo> basketInfoList = deliveryInfo.getBasketInfos();
        if (CollUtil.isEmpty(basketInfoList)) {
            return;
        }
        /*List<String> platProductSkuList = basketInfoList.stream().map(BasketInfo::getProductCustomCode).filter(StrUtil::isNotBlank).collect(Collectors.toList());
        List<PlatformProductDo> platformProductDoList = platformProductService.lambdaQuery()
                .in(PlatformProductDo::getPlatformSku, platProductSkuList)
                .list();
        List<Long> platSkuId = platformProductDoList.stream().map(PlatformProductDo::getId).collect(Collectors.toList());
        Map<Long, List<PlatformProductMappingDo>> platSkuMatchSysSku = new HashMap<>();
        if (CollUtil.isNotEmpty(platSkuId)) {
            platSkuMatchSysSku = platformProductMappingService.lambdaQuery()
                    .in(PlatformProductMappingDo::getPlatformProductId, platSkuId)
                    .list().stream().collect(Collectors.groupingBy(PlatformProductMappingDo::getPlatformProductId));
        }
        Map<Long, ProductDo> productIdMatchDo = new HashMap<>();
        Set<Long> productIdList = platSkuMatchSysSku.values().stream().flatMap(List::stream).map(PlatformProductMappingDo::getSystemProductId).collect(Collectors.toSet());
        if (CollUtil.isNotEmpty(productIdList)) {
            productIdMatchDo = productService.lambdaQuery()
                    .in(ProductDo::getId, productIdList)
                    .list().stream().collect(Collectors.toMap(ProductDo::getId, val -> val, (o1, o2) -> o1));
        }*/
        //积分
        Integer pointSum = basketInfoList.stream().map(BasketInfo::getGrantedShopPoint).reduce(0, Integer::sum);
        platformOrderDo.setPoint(BigDecimal.valueOf(pointSum));
        Collection<BasketInfo> values = basketInfoList.stream().collect(Collectors.toMap(BasketInfo::getProductCustomCode, val -> val, (o1, o2) -> {
            o1.setAmount(o1.getAmount() + o2.getAmount());
            o1.setPrice(o1.getPrice() + o2.getPrice());
            return o1;
        })).values();
        platformOrderDo.setPlatformSku(values.stream().map(item -> item.getProductCustomCode() + "*" + item.getAmount()).collect(Collectors.joining(";")));
        for (BasketInfo basketInfo : values) {
            PlatformOrderProductDo orderProductDo = new PlatformOrderProductDo();
            orderProductDo.setOrderId(platformOrderDo.getId());
            orderProductDo.setPlatformOrderNo(platformOrderDo.getPlatformOrderNo());
            orderProductDo.setPlatformProductName(basketInfo.getProductName());
            orderProductDo.setPlatformSku(basketInfo.getProductCustomCode());
            orderProductDo.setPlatformQty(basketInfo.getAmount());
            orderProductDo.setSku(basketInfo.getProductCustomCode());
            orderProductDo.setQty(basketInfo.getAmount());
            orderProductDo.setItemAmount(BigDecimal.valueOf(basketInfo.getPrice()));
            orderProductDo.setCurrencyCode(CountryEnum.JP.getCurrency());
            orderProductDo.setSkuType(1);
            orderProductDoList.add(orderProductDo);
        }
    }

    @Override
    public void getProduct() throws Exception {
        SearchProductRequest searchProductRequest = new SearchProductRequest();
        searchProductRequest.setLastUpdateFrom("2023-04-25 00:00:00");
        searchProductRequest.setLastUpdateTo("2025-04-27 00:00:00");
        searchProductRequest.setPage(1);
        searchProductRequest.setLimit(1);
        ResultAttributtes[] resultAttributtes = GraphqlResultAttributesBuilder.build(SearchProductResponse.class);
        Map<String, Object> request = new HashMap<>(2);
        request.put("input", new RequestObjectParameter(searchProductRequest));
        SearchProductResponse searchProductResponse = MakeShopGraphqlUtils.postGraphqlQuery(MakeShopShopConfig.builder().url(makeShopConfig.getUrl()).apiKey(makeShopConfig.getApiKey()).token(makeShopConfig.getToken()).build(), "searchProduct", request, SearchProductResponse.class, resultAttributtes);
        log.info(String.valueOf(searchProductResponse));
        if (Objects.nonNull(searchProductResponse) && CollUtil.isNotEmpty(searchProductResponse.getProducts())) {
            List<SearchedProduct> products = searchProductResponse.getProducts();
            Set<String> skuSet = products.stream().map(SearchedProduct::getCustomCode).collect(Collectors.toSet());
            Map<String, PlatformProductDo> platSkuMatchDo = new HashMap<>();
            if (CollUtil.isNotEmpty(skuSet)) {
                platSkuMatchDo = platformProductService.lambdaQuery()
                        .in(PlatformProductDo::getPlatformSku, skuSet)
                        .list().stream().collect(Collectors.toMap(PlatformProductDo::getPlatformSku, val -> val, (o1, o2) -> o1));
            }
            List<PlatformProductDo> platformProductDoList = new ArrayList<>();
            for (SearchedProduct searchedProduct : products) {
                PlatformProductDo platformProductDo = new PlatformProductDo();
//                platformProductDo.setStoreId();
//                platformProductDo.setCompanyId();
//                platformProductDo.setTenantId();
                platformProductDo.setPlatformSku(searchedProduct.getCustomCode());
                platformProductDo.setItemName(searchedProduct.getProductName());
                platformProductDo.setImageUrl(searchedProduct.getMinImageUrl());
                platformProductDo.setPlatLeftQuantity(searchedProduct.getQuantity());
                PlatformProductDo existPlatProduct = platSkuMatchDo.get(searchedProduct.getCustomCode());
                if (existPlatProduct != null) {
                    platformProductDo.setId(existPlatProduct.getId());
                }
                platformProductDoList.add(platformProductDo);
            }
            platformProductService.saveOrUpdateBatch(platformProductDoList);
        }
    }

    @Override
    public void getProductStock() throws Exception {
        SearchProductQuantityRequest searchProductQuantityRequest = new SearchProductQuantityRequest();
        searchProductQuantityRequest.setPage(1);
        searchProductQuantityRequest.setLimit(10);
        ResultAttributtes[] resultAttributtes = GraphqlResultAttributesBuilder.build(SearchProductQuantityResponse.class);
        Map<String, Object> request = new HashMap<>(2);
        request.put("input", new RequestObjectParameter(searchProductQuantityRequest));
        SearchProductQuantityResponse searchProductQuantityResponse = MakeShopGraphqlUtils.postGraphqlQuery(MakeShopShopConfig.builder().url(makeShopConfig.getUrl()).apiKey(makeShopConfig.getApiKey()).token(makeShopConfig.getToken()).build(), "searchProductQuantity", request, SearchProductQuantityResponse.class, resultAttributtes);
        log.info(String.valueOf(searchProductQuantityResponse));
        if (Objects.nonNull(searchProductQuantityResponse) && CollUtil.isNotEmpty(searchProductQuantityResponse.getProductQuantities())) {
            List<SearchedProductQuantity> productQuantities = searchProductQuantityResponse.getProductQuantities();
            Set<String> skuSet = productQuantities.stream().map(SearchedProductQuantity::getSystemCode).collect(Collectors.toSet());
            Map<String, PlatformProductDo> platSkuMatchDo = new HashMap<>();
            if (CollUtil.isNotEmpty(skuSet)) {
                platSkuMatchDo = platformProductService.lambdaQuery()
                        .in(PlatformProductDo::getPlatformSku, skuSet)
                        .list().stream().collect(Collectors.toMap(PlatformProductDo::getPlatformSku, val -> val, (o1, o2) -> o1));
            }
            List<PlatformProductDo> platformProductDoList = new ArrayList<>();
            for (SearchedProductQuantity searchedProductQuantity : productQuantities) {
                PlatformProductDo platformProductDo = new PlatformProductDo();
                //                platformProductDo.setStoreId();
//                platformProductDo.setCompanyId();
//                platformProductDo.setTenantId();
                platformProductDo.setPlatformSku(searchedProductQuantity.getCustomCode());
                platformProductDo.setItemName(searchedProductQuantity.getProductName());
                platformProductDo.setPlatLeftQuantity(searchedProductQuantity.getQuantity());
                PlatformProductDo existPlatProduct = platSkuMatchDo.get(searchedProductQuantity.getSystemCode());
                if (existPlatProduct != null) {
                    platformProductDo.setId(existPlatProduct.getId());
                }
                platformProductDoList.add(platformProductDo);
            }
            platformProductService.saveOrUpdateBatch(platformProductDoList);
        }
    }
}